Page({
  data: {
    currentRiddle: null, // 当前显示的脑筋急转弯问题
    showAnswerFlag: false, // 是否显示答案
  },
  getRiddle() {
    const that = this;
    wx.request({
      url: 'https://apis.tianapi.com/naowan/index',
      method: 'POST',
      data: {
        key: '3999c72f70747aa04ff700113680d4a0',
        num: '1',
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      success: function (res) {
        if (res.data.code === 200 && res.data.result.list && res.data.result.list.length > 0) {
          that.setData({
            currentRiddle: res.data.result.list[0],
            showAnswerFlag: false, // 每次获取新问题，隐藏答案
          });
        } else {
          wx.showToast({
            title: '获取失败',
            icon: 'none',
          });
        }
      },
      fail: function (err) {
        console.log('请求失败', err);
        wx.showToast({
          title: '网络错误',
          icon: 'none',
        });
      },
    });
  },
  showAnswer() {
    this.setData({
      showAnswerFlag: true,
    });
  },
  onLoad(options) {},
  onReady() {},
  onShow() {},
  onHide() {},
  onUnload() {},
  onPullDownRefresh() {
    this.getRiddle();
    wx.stopPullDownRefresh();
  },
  onReachBottom() {},
  onShareAppMessage() {},
});